package com.atgm.mall.gmmallauth.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.atgm.common.exception.BizCodeEnume;
import com.atgm.common.exception.MemberException;
import com.atgm.common.utils.HttpClientUtils;
import com.atgm.common.utils.R;
import com.atgm.common.vo.login.WeiboUser;
import com.atgm.mall.gmmallauth.feign.MemberFeignService;
import com.atgm.mall.gmmallauth.service.OAuthService;
import com.atgm.mall.gmmallauth.vo.MemberEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 社交登录
 */
@Slf4j
@Controller
public class OAuth2Controller {

    @Autowired
    private MemberFeignService memberFeignService;

    @Autowired
    private OAuthService oAuthService;

    /**
     * 微博登录
     * @return
     */
    @GetMapping("/weibo/login")
    public String weiboLogin(@RequestParam("code") String code){
        String memberId = oAuthService.handlerWeiboLogin(code);
        return "redirect:http://gmmall.com/#/?id=" + memberId;
    }

}
